package com.example.cs_jump.Util;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.cs_jump.Bean.JsonBean;

import java.util.ArrayList;
import java.util.List;

public class SqliteHelper {
   private static List<JsonBean> datas;
    private  static  Sqlite sqlite;
    private  static SQLiteDatabase db;

    public static List<JsonBean> queryData(Context context,String name){
        sqlite =new Sqlite(context.getApplicationContext());
        db=sqlite.getWritableDatabase();
        datas=new ArrayList<>();
        datas.clear();
        Cursor cursor=db.query(name,null,null,null,null,null,null);
        if (cursor!=null&&cursor.getCount()>0){
           // Log.d(name,"------------------------------------");
            //Log.d(name,"开始查询");
            while (cursor.moveToNext()){
                String id=cursor.getString(cursor.getColumnIndex("id"));
                String title=cursor.getString(cursor.getColumnIndex("title"));
                String brief=cursor.getString(cursor.getColumnIndex("brief"));
                String tickrate=cursor.getString(cursor.getColumnIndex("tickrate"));
                String cover=cursor.getString(cursor.getColumnIndex("cover"));
                JsonBean jsonBean=new JsonBean(id,title,brief,tickrate,cover);
                datas.add(jsonBean);
            }
            Log.d(name,datas.toString());
        }
        cursor.close();
        db.close();
        return datas;
    }

}
